﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using VirtualPress.Tool.Framework;

namespace VirtualPress.Infrastructure.Entities.Repository
{
    [Table("T_Article")]
    public class T_Article : IEntity<T_Article>
    {
        [Key]
        [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(64)]
        public string UserName { get; set; }
        /// <summary>
        /// 稿件状态
        /// </summary>
        public int Status { get; set; }
        /// <summary>
        /// 稿件归属
        /// </summary>
        public int ArticleType { get; set; }
        /// <summary>
        /// 所属期刊Id
        /// </summary>
        public int Peri_Id { get; set; }
        /// <summary>
        /// 所装订入期刊号
        /// </summary>
        public int PeriItem_Id { get; set; }
        /// <summary>
        /// 所属会议Id
        /// </summary>
        public int Conference_Id { get; set; }
        /// <summary>
        /// 所属会议项Id
        /// </summary>
        public int ConferenceItem_Id { get; set; }
        /// <summary>
        /// 稿件编号
        /// </summary>
        [Column(TypeName="varchar")]
        [StringLength(64)]
        public string Code { get; set; }
        /// <summary>
        /// 稿件类型
        /// </summary>
        public int Type { get; set; }
        /// <summary>
        /// 领域代码
        /// </summary>
        public int FiedCode { get; set; }
        /// <summary>
        /// 子领域代码
        /// </summary>
        public int SubFiedCode { get; set; }
        /// <summary>
        /// 中图分类号
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(64)]
        public string ZTFLH { get; set; }
        /// <summary>
        /// 文献标识码
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(64)]
        public string WM { get; set; }
        /// <summary>
        /// 稿件标题
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(128)]
        public string Title { get; set; }
        /// <summary>
        /// 稿件标题_EN
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string Title_EN { get; set; }
        /// <summary>
        /// 摘要
        /// </summary>
        [Column(TypeName = "text")]
        public string Abstract { get; set; }
        /// <summary>
        /// 摘要_EN
        /// </summary>
        [Column(TypeName = "text")]
        public string Abstract_EN { get; set; }
        /// <summary>
        /// 关键词
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string KeyWords { get; set; }
        /// <summary>
        /// 关键词_EN
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(512)]
        public string KeyWords_EN { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime SubmitTime { get; set; }
        public int PageSize { get; set; }
        /// <summary>
        /// 支付总额
        /// </summary>
        public int TotalPay { get; set; }

        /// <summary>
        /// 稿件范围
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(1024)]
        public string GJFW { get; set; }

        [Column(TypeName="bit")]
        public bool IsDelete { get; set; }

        /// <summary>
        /// 专家推荐材料
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string Recommendation { get; set; }

        public int DownloadNumber { get; set; }
        public int VisitNumber { get; set; }

        public override T_Article Find(System.Linq.Expressions.Expression<Func<T_Article, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.Article.FirstOrDefault(where);
                if (item != null)
                {
                    this.UserName = item.UserName;
                    this.Abstract = item.Abstract;
                    this.Abstract_EN = item.Abstract_EN;
                    this.ArticleType = item.ArticleType;
                    this.Code = item.Code;
                    this.CreateTime = item.CreateTime;
                    this.FiedCode = item.FiedCode;
                    this.Id = item.Id;
                    this.KeyWords = item.KeyWords;
                    this.KeyWords_EN = item.KeyWords_EN;
                    this.Peri_Id = item.Peri_Id;
                    this.SubmitTime = item.SubmitTime;
                    this.Title = item.Title;
                    this.Title_EN = item.Title_EN;
                    this.Type = item.Type;
                    this.WM = item.WM;
                    this.Conference_Id = item.Conference_Id;
                    this.ZTFLH = item.ZTFLH;
                    this.PeriItem_Id = item.PeriItem_Id;
                    this.PageSize = item.PageSize;
                    this.SubFiedCode = item.SubFiedCode;
                    this.Status = item.Status;
                    this.TotalPay = item.TotalPay;
                    this.IsDelete = item.IsDelete;
                    this.GJFW = item.GJFW;
                    this.Recommendation = item.Recommendation;
                    this.DownloadNumber = item.DownloadNumber;
                    this.VisitNumber = item.VisitNumber;
                    this.ConferenceItem_Id = item.ConferenceItem_Id;
                    return this;
                }
                return null;
            }
        }
        public override T_Article Find(string key)
        {
            int id = Int32.Parse(key);
            return Find(c => c.Id == id);
        }
        public override bool Any(System.Linq.Expressions.Expression<Func<T_Article, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.Article.Any(where);
            }
        }
    }
}
